package hongcheng.code_generator.entity.config;

import hongcheng.code_generator.exception.CustomException;

/**
 * 	controller层代码生成配置
 * */
public class ControllerJavaConfig {

	/***
	 * 	是否rest风格接口
	 * */
	private boolean isRestApi = true;
	/***
	 * 	是否是否捕获异常
	 * */
	private boolean isCatchException = true;
	/***
	 * 	是否全rest风格接口
	 * */
	private String methodRequestMapping = MethodRequestMapping.ALL.getRequestMapping();
	
	/**
	 * 	是否使用“Swagger” ，默认使用。
	 * */
	private boolean isUserSwagger = true;
	
	public boolean getIsUserSwagger() {
		return isUserSwagger;
	}

	public void setIsUserSwagger(boolean isUserSwagger) {
		this.isUserSwagger = isUserSwagger;
	}
	
	/***
	 * 	接口请求方式枚举
	 * */
	public enum MethodRequestMapping{
		ALL("RequestMapping"),
		GET("GetMapping"),
		POST("PostMapping"),
		PUT("PutMapping"),
		DELETE("DeleteMapping");
		
		private String requestMapping;
		
		private MethodRequestMapping(String requestMapping) {
			this.requestMapping = requestMapping;
		}
		
		public String getRequestMapping() {
			return this.requestMapping;
		}
		
		public static MethodRequestMapping fromRequestMapping(String requestMapping) {
			MethodRequestMapping[] methodRequestMappings = MethodRequestMapping.values();
			for(MethodRequestMapping methodRequestMapping:methodRequestMappings) {
				if(methodRequestMapping.requestMapping.equals(requestMapping.trim())) {
					return methodRequestMapping;
				}
			}
			throw new CustomException("找不到requestMapping为{}的枚举：" , requestMapping)  ;
		}
	}



	public boolean getIsRestApi() {
		return isRestApi;
	}



	public boolean getIsCatchException() {
		return isCatchException;
	}



	public String getMethodRequestMapping() {
		return methodRequestMapping;
	}



	public void setIsRestApi(boolean isRestApi) {
		this.isRestApi = isRestApi;
	}



	public void setIsCatchException(boolean isCatchException) {
		this.isCatchException = isCatchException;
	}



	public void setMethodRequestMapping(MethodRequestMapping methodRequestMapping) {
		this.methodRequestMapping = methodRequestMapping.getRequestMapping();
	}
	
	
}
